import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, DelDataButton, ExamineButton } from '../Common/options'
import { BeamSeat } from '../Common/Conversion'

export const BeamProduceRecordDetail = async ({ OptionsEvent, oneData, Permission, actionRef }) => {
    const ClientData = JSON.parse(localStorage.getItem('ClientData'))
    const beamSeatUuid = await BeamSeat()
    let dataList = {
        hideInSearch: true,
        pageSize: 10,
        classification: 'TableModal',
        get: API_LIST()['getBeamProduceRecordDetail'],
        added: 'posBeamProduceRecordDetail',
        params: { beamProduceRecordUuid: oneData.uuid },
        initialValues: { beamProduceRecordUuid: oneData.uuid },
        options: [
            Permission.findIndex(v => v.uuid === 'dbcacb26-1bde-4d14-8ebc-ee63e9abb9a2') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            {
                title: 'BeamProduceRecordUuid',
                dataIndex: 'beamProduceRecordUuid',
                valueType: 'hidden',
                hideInTable: true,
            },
            {
                title: '工序',
                dataIndex: 'processUuid',
                search: false,
                valueEnum: ClientData.process,
                valueType: 'select',
            },
            {
                title: '台座',
                dataIndex: 'beamSeatUuid',
                search: false,
                valueType: 'select',
                valueEnum: beamSeatUuid,
            },
            {
                title: '生产日期',
                dataIndex: 'produceDate',
                search: false,
                valueType: 'Date',
                showTime: true,
            },
            {
                title: '状态',
                dataIndex: 'auditStatus',
                search: false,
                valueType: 'select',
                hideInAdded: true,
                hideInModify: true,
                valueEnum: BuiltInData.auditStatus,
                width: 150,
            },
            commonTableList.createUserName,
            commonTableList.createTime,

            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { auditStatus, uuid } = record
                    return [
                        auditStatus === 0 && (
                            <ExamineButton
                                key="one"
                                title="合格"
                                data={{
                                    actionRef,
                                    OptionsEvent,
                                    url: 'putBeamProduceRecordDetail',
                                    smallTitle: '审核',
                                }}
                                options={[
                                    {
                                        title: '合格',
                                        type: 'primary',
                                        emit: {
                                            data: { uuid, auditStatus: 1, beamProduceRecordUuid: oneData.uuid },
                                            path: [uuid],
                                        },
                                    },
                                    { title: '取消', type: 'link', emit: 'off' },
                                ]}
                            />
                        ),
                        auditStatus === 0 && (
                            <ExamineButton
                                key="two"
                                title="不合格"
                                danger={true}
                                data={{
                                    actionRef,
                                    OptionsEvent,
                                    url: 'putBeamProduceRecordDetail',
                                    smallTitle: '审核',
                                }}
                                options={[
                                    {
                                        title: '不合格',
                                        type: 'primary',
                                        danger: true,
                                        emit: {
                                            data: { uuid, auditStatus: 2, beamProduceRecordUuid: oneData.uuid },
                                            path: [uuid],
                                        },
                                    },
                                    { title: '取消', type: 'link', emit: 'off' },
                                ]}
                            />
                        ),
                        auditStatus === 0 && (
                            <ExamineButton
                                key="thr"
                                title="销毁"
                                danger={true}
                                data={{
                                    actionRef,
                                    OptionsEvent,
                                    url: 'putBeamProduceRecordDetail',
                                    smallTitle: '销毁',
                                }}
                                options={[
                                    {
                                        title: '销毁',
                                        type: 'primary',
                                        danger: true,
                                        emit: {
                                            data: { uuid, auditStatus: 0, beamProduceRecordUuid: oneData.uuid },
                                            path: [uuid],
                                        },
                                    },
                                    { title: '取消', type: 'link', emit: 'off' },
                                ]}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'fc616397-ebb3-4046-b3f9-7d41df4a65c5') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url="BeamProduceRecordDetail"
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }

    return dataList
}
